package com.donzell.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.donzell.dao.UserRepository;
import com.donzell.model.bean.Demo;
import com.donzell.model.bean.User;
@RestController
@RequestMapping("hello")
public class HelloController {
	@Autowired
	private UserRepository userRepository;
	
    @RequestMapping("/add")
    public String add(@RequestParam(defaultValue="word") String name) {
    	String pass = "5555555555";
    	
//    	userRepository.save(new User(111,"aaa", pass));
//		userRepository.save(new User(112,"bbb", pass));
//		userRepository.save(new User(113,"ccc", pass));
//		userRepository.save(new User(114,"ddd", pass));
//		userRepository.save(new User(115,"eee", pass));
    	 return "hello  "+name+"!"+userRepository.findAll().size(); 
    }
    
    
    @RequestMapping("/")
    public String index(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("name", "hh1");
        map.addAttribute("bookTitle", "tt444");
        // return模板文件的名称，对应src/main/resources/templates/welcome.html
        return "index";
    }
	
	
	@RequestMapping("index")
	public String index(@RequestParam(defaultValue="word") String name){
		 return "hello  "+name+"!";  
	}
	
	@RequestMapping("img")
	public String img(){
		return "hello world <img src=\"/myres/demo.png\">";
	}
}
